//
//  QSNavigationBar.m
//  QSSmarkPark-iOS
//
//  Created by SJ on 2018/8/31.
//  Copyright © 2018年 QiSheng. All rights reserved.
//

#import "QSNavigationBar.h"

@interface QSNavigationBar ()

@property (nonatomic,strong) UILabel *titleLabel;

@end

@implementation QSNavigationBar

- (instancetype)init {
    return [self initWithFrame:CGRectMake(0, 0, kScreenWidth,kNavgationBarHeight)];
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.navBackgroundView = [[UIView alloc] initWithFrame:frame];
        self.navBackgroundView.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.navBackgroundView];
        
        self.leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(17, kStatusBarHeight, 50, 44)];
        self.leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [self.leftBtn addTarget:self action:@selector(leftButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.leftBtn setImage:[UIImage imageNamed:@"ic_navigation_back"] forState:UIControlStateNormal];
        [self addSubview:self.leftBtn];
        
        self.titleLabel = [[ UILabel alloc] initWithFrame:CGRectMake(self.leftBtn.right + 10, kStatusBarHeight, self.width - 140, 44)];
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        self.titleLabel.textColor = [UIColor QSColorWhiteFFFFFF];
        self.titleLabel.font = [UIFont QSBoldFontOfSize18];
        [self addSubview:self.titleLabel];
        
        self.rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(kScreenWidth - 67, kStatusBarHeight, 50, 44)];
        self.rightBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        [self.rightBtn addTarget:self action:@selector(rightButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        self.rightBtn.titleLabel.font = [UIFont QSFontOfSize15];
        [self addSubview:self.rightBtn];
    }
    return self;
}

#pragma mark - ***************** Public Methods
+ (instancetype)defaultNavgationBar {
    return [[QSNavigationBar alloc] init];
}

#pragma mark - ***************** Event Response
- (void)rightButtonClick:(UIButton *)button {
    if (self.rightAction) {
        self.rightAction(button);
    }
}

- (void)leftButtonClick:(UIButton *)button {
    if (self.leftAction) {
        self.leftAction(button);
    }
}

#pragma mark - ***************** Setter Getter
- (void)setTitle:(NSString *)title {
    _title = title;
    self.titleLabel.text = title;
}

- (void)setLeftButtonImage:(UIImage *)leftButtonImage {
    _leftButtonImage = leftButtonImage;
    [self.leftBtn setImage:leftButtonImage forState:UIControlStateNormal];
}

- (void)setLeftButtonTitle:(NSString *)leftButtonTitle {
    _leftButtonTitle = leftButtonTitle;
    [self.leftBtn setTitle:leftButtonTitle forState:UIControlStateNormal];
}

- (void)setTitleColor:(UIColor *)titleColor {
    _titleColor = titleColor;
    self.titleLabel.textColor = titleColor;
}

- (void)setLeftButtonTitleColor:(UIColor *)leftButtonTitleColor {
    _leftButtonTitleColor = leftButtonTitleColor;
    [self.leftBtn setTitleColor:leftButtonTitleColor forState:UIControlStateNormal];
}

- (void)setRightButtonImage:(UIImage *)rightButtonImage {
    _rightButtonImage = rightButtonImage;
    [self.rightBtn setImage:rightButtonImage forState:UIControlStateNormal];
}

- (void)setRightButtonTitle:(NSString *)rightButtonTitle {
    _rightButtonTitle = rightButtonTitle;
    [self.rightBtn setTitle:rightButtonTitle forState:UIControlStateNormal];
}

- (void)setRightButtonTitleColor:(UIColor *)rightButtonTitleColor {
    _rightButtonTitleColor = rightButtonTitleColor;
    [self.rightBtn setTitleColor:rightButtonTitleColor forState:UIControlStateNormal];
}


@end
